package org.ns.framework.datasource.config;

import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.ns.framework.datasource.anns.MybatisConfig;

public interface MybatisConfiguration {
	/**
	 * 数据源名称
	 */
	default String[] getDataSourceName() {
		MybatisConfig mybatisConfig = this.getClass().getAnnotation(MybatisConfig.class);
		if (mybatisConfig == null) {
			return new String[] { "*" };
		} else {
			return mybatisConfig.datasources();
		}
	}
	/**
	 * 进行配置的说.
	 * @param mybatisParam
	 */
	void configuration(MybatisParam mybatisParam);

	public static class MybatisParam {
		private String dataSourceName;
		private Configuration configuration;
		private SqlSessionFactory sqlSessionFactory;

		public MybatisParam(String dataSourceName, Configuration configuration, SqlSessionFactory sqlSessionFactory) {
			super();
			this.dataSourceName = dataSourceName;
			this.configuration = configuration;
			this.sqlSessionFactory = sqlSessionFactory;
		}

		public Configuration getConfiguration() {
			return configuration;
		}

		public String getDataSourceName() {
			return dataSourceName;
		}

		public SqlSessionFactory getSqlSessionFactory() {
			return sqlSessionFactory;
		}
	}
}
